package Test;

import Domain.User;

import java.util.ArrayList;

public class Test20 {
    public static void main(String[] args) {
        ArrayList<User> list = new ArrayList<>();

        list.add(new User("张三",18,"男"));
        list.add(new User("李四",18,"女"));
        list.add(new User("王五",14,"男"));
        list.add(new User("赵六",20,"男"));
        list.add(new User("老七",17,"女"));

        ArrayList<User> newList= getUser(list);

        for (int i = 0; i < newList.size(); i++) {
            User us = newList.get(i);
            System.out.println(us.getName()+"\t"+us.getAge()+"\t"+us.getSex());
        }


    }

    public static ArrayList<User> getUser(ArrayList<User> users){
        ArrayList<User> newlist = new ArrayList<>();
        for (int i = 0; i < users.size(); i++) {
            User user = users.get(i);
            if(user.getAge() >= 18){
                if("男".equals(user.getSex())){
                    newlist.add(user);
                }
            }
        }
        return newlist;
    }
}
